package 实验6_4;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Example19_7 extends Applet implements Runnable
{Thread 红色球,兰色球; Graphics redPen,bluePen;int t=0;
  public void init()
  { 红色球=new Thread(this); 兰色球=new Thread(this);
   redPen=getGraphics();
  bluePen=getGraphics();
   redPen.setColor(Color.red);
  bluePen.setColor(Color.blue);
  }
  public void start()
  {红色球.start();兰色球.start();
  }
  public void run()
  { while(true)
   { t=t+1;
   if(Thread.currentThread()==红色球) 
   {if(t>100) t=0;
      redPen.clearRect(0,0,110,400);
      redPen.fillOval(50,(int)(1.0/2*t*9.8),5,5);
      try{红色球.sleep(40);}
        catch(InterruptedException e){}
     }
     else if(Thread.currentThread()==兰色球)
      {bluePen.clearRect(120,0,900,500); 
       bluePen.fillOval(120+7*t,(int)(1.0/2*t*9.8),5,5);
        try{兰色球.sleep(40);}
        catch(InterruptedException e){}
      } 
    }   
  } 
}